//
//  JMAddController.m
//  PhotoLock
//
//  Created by 赵俊明 on 2017/7/15.
//  Copyright © 2017年 赵俊明. All rights reserved.
//

#import "JMAddController.h"
@interface JMAddController ()<UITextFieldDelegate>
@property (nonatomic, weak) UITextField *textF;
@end

@implementation JMAddController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = JMBaseColor;
    self.title = @"Creat album";
    [self configUI];
    
}

- (void)leftBtn:(UIButton *)sender
{
    if (_textF.text.length>0) {
    
        [JMHelper creatFolder:_textF.text dir:kPhotos];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

- (void)rightBtn:(UIButton *)sender
{
    if (_textF.text.length>0) {
     
        [JMHelper creatFolder:_textF.text dir:kVideos];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

- (void)leftTitleAction:(UIBarButtonItem *)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    NSLog(@"%@", textField.text);
    return YES;
}

- (void)configUI
{
    UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithTitle:@"Cancle" style:(UIBarButtonItemStyleDone) target:self action:@selector(leftTitleAction:)];
    self.navigationItem.leftBarButtonItem = left;
    
    UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(10, 64, self.view.width-20, 64)];
    name.text = @"Name";
    [self.view addSubview:name];
    
    UITextField *textF = [[UITextField alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(name.frame), self.view.width, 44)];
    textF.delegate = self;
    textF.placeholder = @"Enter Album Name ...";
    textF.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:textF];
    self.textF = textF;
    
    UILabel *type = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(textF.frame), self.view.width-20, 64)];
    type.text = @"type";
    [self.view addSubview:type];
    
    CGFloat margin = self.view.width/8;
    UIButton *leftBtn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    leftBtn.backgroundColor = [UIColor whiteColor];
    leftBtn.tintColor = [UIColor blackColor];
    leftBtn.frame = CGRectMake(margin, CGRectGetMaxY(type.frame)+30, self.view.width/4, self.view.width/4);
    [leftBtn setTitle:@"Photo" forState:(UIControlStateNormal)];
    [leftBtn addTarget:self action:@selector(leftBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:leftBtn];
    
    UIButton *rightBtn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    rightBtn.backgroundColor = [UIColor whiteColor];
    rightBtn.tintColor = [UIColor blackColor];
    rightBtn.frame = CGRectMake(self.view.width/2 + margin, CGRectGetMaxY(type.frame)+30, self.view.width/4, self.view.width/4);
    [rightBtn setTitle:@"Video" forState:(UIControlStateNormal)];
    [rightBtn addTarget:self action:@selector(rightBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:rightBtn];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
